package udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Server
 * Package: udp
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-14
 * Time: 17:11
 */

public class Server {
    public static void main(String[] args) throws IOException {

        //UDP接收数据
        //1.创建连接
        DatagramSocket socket = new DatagramSocket(9999);

        //创建数据对象 用于接收发送端 发来的数据
        byte[] buffer = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buffer,0,buffer.length);


        //接收数据
        socket.receive(packet);

        //打印数据

        String s = new String(packet.getData(),packet.getLength());
        System.out.println(s);

        //关闭资源
        socket.close();
    }
}
